<template>
  <!-- 选择客户 -->
    <el-dialog title="信息" :visible.sync="openSelectCustomer" width="800px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form ref="form" :model="formQuery" label-width="100px" :inline="true" v-show="showSearch" @submit.native.prevent>
        <el-form-item label="客户" prop="khmc">
          <el-input
            v-model="formQuery.khmc"
            placeholder="请输入客户"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery">搜 索</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="customerList"
        row-key="khid"
      >
        <af-table-column label="操作" align="center" class-name="small-padding fixed-width" >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleSelect(scope.row)"
            >录入</el-button>
          </template>
        </af-table-column>
        <af-table-column prop="khmc" label="客户"></af-table-column>
      </el-table>
       <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-dialog>
</template>

<script>
import { selectCustomer } from "@/api/storage/commonGoods/warehouseIn";

export default {
  name: "CWarehouseInSelectCustomer",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //表格加载
      loading: true,
      //弹窗状态
      openSelectCustomer: false,
      // 查询参数
      formQuery: {
       	all: "",
        isBa: "",
        issell: "",
        issh: "",
        khmc: "",
        khpb: 0,
        name: "",
        num: "",
        shopId: 0,
        spckid: "",
        spckidis: [],
      },
      //行数据
      customerList:[],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  methods: {
    /**获取仓库信息 */
    getList() {
      this.loading = true
      selectCustomer(this.formQuery, this.pageNum, this.pageSize).then(response => {
        this.customerList = this.handleTree(response.rows, "khid");
        this.total = response.total
        this.loading = false
      });
    },
    /**仓库搜索 */
    handleQuery() {
        this.getList()
    },
    /** 选中仓库*/
    handleSelect(row) {
      this.changeSelectCustomer()
      this.$emit('customerSelected', row)
    },
     /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /**改变窗口状态 */
    changeSelectCustomer() {
      this.openSelectCustomer = !this.openSelectCustomer;
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭弹窗 */
    close() {
      this.changeSelectCustomer()
    },
    /**打开弹窗 */
    open(row) {
        this.changeSelectCustomer()
        this.getList()
        this.form = row
    }
  }
};
</script>
